% 2022-05-14   not yet integrated


% !Mode:: "TeX:UTF-8:Main"
\documentclass{article}

%\input{regression-test}


\usepackage{footmisc}
\usepackage{hyperref}
\ExplSyntaxOn\makeatletter
%ref attribute absfootnote
\ref_attribute_gset:nnnn
  { absfootnote } {0} { now }
  { \int_use:N \c@absfootnote }

\cs_generate_variant:Nn\ref_label:nn{nV}

% a list for the attributes to label, currently only absfootnote
\clist_new:N\g__kernel_extref_clist
\clist_gput_right:Nn\g__kernel_extref_clist{absfootnote}

% extend the label command
\def\label#1{
  \@bsphack
  \ref_label:nV{#1}\g__kernel_extref_clist
  \protected@write\@auxout{}%
         {\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
  \@esphack}

% make the reference id customizable:
\tl_new:N  \__tag_FEMARK_id_tl
\tl_set:Nn \__tag_FEMARK_id_tl  {\the\c@absfootnote}

\cs_set:Npn \tag@FEMark #1 {
  \tag_if_loaded:TF
     {
       \tag_mc_end_push:
       \exp_args:Nx
       \tag_struct_begin:n{tag=Lbl,ref=fn.\__tag_FEMARK_id_tl}
       \tag_mc_begin:n{tag=Lbl}
       \IfPackageLoadedTF{hyperref}{ \hyper@linkstart
         {link}{fn.\__tag_FEMARK_id_tl} }{}
       #1
      \IfPackageLoadedTF{hyperref}{ \hyper@linkend }{}
      \tag_mc_end:
      \tag_struct_end:
      \tag_mc_begin_pop:n{}
     }
     { #1 }
}

% copy back to \@kernel@process@makefnmark
\cs_set_eq:NN \@kernel@process@makefnmark \tag@FEMark

% set the id_tl to the default c@absfootnote
\DeclareDocumentCommand\footnote {o+m} {
  \fn_step_fnmark:nn {#1} \@mpfn
  \cs_set_eq:NN \__fnote_footnotemark_finish: \prg_do_nothing:
  \tl_set:Nn \__tag_FEMARK_id_tl  {\the\c@absfootnote} %<--------?
  \@footnotemark
  \cs_set_eq:NN \__fnote_footnotemark_finish: \__fnote_finish:
  \@footnotetext {#2}
  \__fnote_footnotemark_finish:
}

% use the label value here
\DeclareDocumentCommand\footref {m}{%
  \begingroup
    \IfPackageLoadedTF{hyperref}
     {\unrestored@protected@xdef\@thefnmark{\ref*{#1}}}% no link!
     {\unrestored@protected@xdef\@thefnmark{\ref{#1}}}%
  \endgroup
  \tl_set:Nn \__tag_FEMARK_id_tl  {\ref_value:nnn {#1}{absfootnote}{1}}
  \@footnotemark
}

\ExplSyntaxOff

\showoutput

\begin{document}

%\START

Test\footnote{A}xxx\footnote{\label{foo}B}xxx\footnote[7]{C}


\renewcommand\thefootnote{\fnsymbol{footnote}}


Test\footnote{D} and\footnote{E}xxx\footref{foo}



\newpage
%\OMIT
\end{document}
